<!doctype html>
<html class="no-js" lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>
    
  如何生成一个egg包以及如果加载egg包 - NeilBlog
  
  </title>
  
  
  <link href="atom.xml" rel="alternate" title="NeilBlog" type="application/atom+xml">
    <link rel="stylesheet" href="asset/css/foundation.min.css" />
    <link rel="stylesheet" href="asset/css/docs.css" />
    <script src="asset/js/vendor/modernizr.js"></script>
    <script src="asset/js/vendor/jquery.js"></script>
  <script src="asset/highlightjs/highlight.pack.js"></script>
  <link href="asset/highlightjs/styles/github.css" media="screen, projection" rel="stylesheet" type="text/css">
  <script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript">
  function before_search(){
    var searchVal = 'site: ' + document.getElementById('search_input').value;
    document.getElementById('search_q').value = searchVal;
    return true;
  }
</script>
  </head>
  <body class="antialiased hide-extras">
    
    <div class="marketing off-canvas-wrap" data-offcanvas>
      <div class="inner-wrap">


<nav class="top-bar docs-bar hide-for-small" data-topbar>


  <section class="top-bar-section">
  <div class="row">
      <div style="position: relative;width:100%;"><div style="position: absolute; width:100%;">
        <ul id="main-menu" class="left">
        
        <li id=""><a target="self" href="index.html">Home</a></li>
        
        <li id=""><a target="_self" href="archives.html">Archives</a></li>
        
        </ul>

        <ul class="right" id="search-wrap">
          <li>
<form target="_blank" onsubmit="return before_search();" action="https://google.com/search" method="get">
    <input type="hidden" id="search_q" name="q" value="" />
    <input tabindex="1" type="search" id="search_input"  placeholder="Search"/>
</form>
</li>
          </ul>
      </div></div>
  </div>
  </section>

</nav>

        <nav class="tab-bar show-for-small">
  <a href="javascript:void(0)" class="left-off-canvas-toggle menu-icon">
    <span> &nbsp; NeilBlog</span>
  </a>
</nav>

<aside class="left-off-canvas-menu">
      <ul class="off-canvas-list">
        
        <li><a target="self" href="index.html">Home</a></li>
        
        <li><a target="_self" href="archives.html">Archives</a></li>
        

    <li><label>Categories</label></li>

        
            <li><a href="Python.html">Python</a></li>
        
            <li><a href="opentstack-neutron.html">opentstack-neutron</a></li>
        
            <li><a href="%E6%8A%80%E6%9C%AF%E5%91%A8%E8%BE%B9.html">技术周边</a></li>
        
            <li><a href="%E9%A1%B9%E7%9B%AE%E7%AC%94%E8%AE%B0.html">项目笔记</a></li>
         

      </ul>
    </aside>

<a class="exit-off-canvas" href="#"></a>


        <section id="main-content" role="main" class="scroll-container">
        
       

 <script type="text/javascript">
  $(function(){
    $('#menu_item_index').addClass('is_active');
  });
</script>
<div class="row">
  <div class="large-8 medium-8 columns">
      <div class="markdown-body article-wrap">
       <div class="article">
          
          <h1>如何生成一个egg包以及如果加载egg包</h1>
     
        <div class="read-more clearfix">
          <span class="date">2019/6/28</span>

          <span>posted in&nbsp;</span> 
          
              <span class="posted-in"><a href='Python.html'>Python</a></span>
           
         
          <span class="comments">
            

            
          </span>

        </div>
      </div><!-- article -->

      <div class="article-content">
      <ul>
<li>
<a href="#toc_0">制作egg包</a>
<ul>
<li>
<a href="#toc_1">setuptools 工具安装包</a>
</li>
</ul>
</li>
<li>
<a href="#toc_2">代码加载egg包</a>
</li>
</ul>


<blockquote>
<p>参考资料<br/>
<a href="https://www.jianshu.com/p/ea9973091fdf">https://www.jianshu.com/p/ea9973091fdf</a></p>
</blockquote>

<h2 id="toc_0">制作egg包</h2>

<ol>
<li><p>创建包目录结构，eggtest是安装后的包名称。</p>
<pre><code class="language-text">bogon:eggpackage ulysses$ tree -a
.<br/>
├── eggtest #安装后对应的包名<br/>
│   ├── __init__.py<br/>
│   └── create_egg.py<br/>
└── setup.py<br/>
2 directories, 5 files
</code></pre></li>
<li><p>编写setup.py文件</p>
<pre><code class="language-text">from setuptools import setup, find_packages
setup(<br/>
    name=&quot;create_egg&quot;, # egg包名称，不是调用时的包名称<br/>
    version=&quot;0.1&quot;,<br/>
    packages=find_packages(), #通过find_packages在当前路径下自动查找包<br/>
)
</code></pre></li>
<li><p>执行python3 setup.py bdist_egg 显示生成后目录结构</p>
<pre><code class="language-text">bogon:eggpackage ulysses$ tree -a
.<br/>
├── build<br/>
│   ├── bdist.macosx-10.9-x86_64<br/>
│   └── lib<br/>
│       └── eggtest<br/>
│           ├── __init__.py<br/>
│           └── create_egg.py<br/>
├── create_egg.egg-info<br/>
│   ├── PKG-INFO<br/>
│   ├── SOURCES.txt<br/>
│   ├── dependency_links.txt<br/>
│   └── top_level.txt<br/>
├── dist<br/>
│   └── create_egg-0.1-py3.7.egg<br/>
├── eggtest<br/>
│   ├── __init__.py<br/>
│   └── create_egg.py<br/>
└── setup.py<br/>
8 directories, 12 files
</code></pre></li>
<li><p>通过解压命令显示包内容</p></li>
</ol>

<pre><code class="language-text">bogon:eggpackage ulysses$ unzip -l dist/create_egg-0.1-py3.7.egg
Archive:  dist/create_egg-0.1-py3.7.egg
  Length      Date    Time    Name
---------  ---------- -----   ----
      182  06-28-2019 19:42   EGG-INFO/PKG-INFO
      186  06-28-2019 19:42   EGG-INFO/SOURCES.txt
        1  06-28-2019 19:42   EGG-INFO/dependency_links.txt
        8  06-28-2019 19:42   EGG-INFO/top_level.txt
        1  06-28-2019 19:42   EGG-INFO/zip-safe
      160  06-28-2019 14:37   eggtest/__init__.py
      111  06-28-2019 17:37   eggtest/create_egg.py
---------                     -------
     1260                     9 files
</code></pre>

<ol>
<li><p>通过python3 setup.py install 安装egg包</p>
<pre><code class="language-text">安装后路径：
 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/create_egg-0.1-py3.7.egg
</code></pre></li>
<li><p>测试包安装结果</p>
<pre><code class="language-text">bogon:eggpackage ulysses$ python3
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) <br/>
[Clang 6.0 (clang-600.0.57)] on darwin<br/>
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br/>
&gt;&gt;&gt; import eggtest<br/>
&gt;&gt;&gt; eggtest.creat_egg()<br/>
hello world<br/>
&gt;&gt;&gt; 
</code></pre></li>
</ol>

<h3 id="toc_1">setuptools 工具安装包</h3>

<h2 id="toc_2">代码加载egg包</h2>


    

      </div>

      <div class="row">
        <div class="large-6 columns">
        <p class="text-left" style="padding:15px 0px;">
      
          <a href="15617044001877.html" 
          title="Previous Post: neutron 调试方法">&laquo; neutron 调试方法</a>
      
        </p>
        </div>
        <div class="large-6 columns">
      <p class="text-right" style="padding:15px 0px;">
      
          <a  href="15616868047861.html" 
          title="Next Post: ```">``` &raquo;</a>
      
      </p>
        </div>
      </div>
      <div class="comments-wrap">
        <div class="share-comments">
          

          

          
        </div>
      </div>
    </div><!-- article-wrap -->
  </div><!-- large 8 -->




 <div class="large-4 medium-4 columns">
  <div class="hide-for-small">
    <div id="sidebar" class="sidebar">
          <div id="site-info" class="site-info">
            
                <h1>NeilBlog</h1>
                <div class="site-des"></div>
                <div class="social">











  <a target="_blank" class="rss" href="atom.xml" title="RSS">RSS</a>
                
              	 </div>
          	</div>

             

              <div id="site-categories" class="side-item ">
                <div class="side-header">
                  <h2>Categories</h2>
                </div>
                <div class="side-content">

      	<p class="cat-list">
        
            <a href="Python.html"><strong>Python</strong></a>
        
            <a href="opentstack-neutron.html"><strong>opentstack-neutron</strong></a>
        
            <a href="%E6%8A%80%E6%9C%AF%E5%91%A8%E8%BE%B9.html"><strong>技术周边</strong></a>
        
            <a href="%E9%A1%B9%E7%9B%AE%E7%AC%94%E8%AE%B0.html"><strong>项目笔记</strong></a>
         
        </p>


                </div>
              </div>

              <div id="site-categories" class="side-item">
                <div class="side-header">
                  <h2>Recent Posts</h2>
                </div>
                <div class="side-content">
                <ul class="posts-list">
	      
		      
			      <li class="post">
			        <a href="15623333744762.html">bytes/string转换</a>
			      </li>
		     
		  
		      
			      <li class="post">
			        <a href="15622929808447.html">netconf client通信框架</a>
			      </li>
		     
		  
		      
			      <li class="post">
			        <a href="15621228986145.html">devstack 安装openstack</a>
			      </li>
		     
		  
		      
			      <li class="post">
			        <a href="15620552731750.html">neutron agent 使用netconf向设备下发配置</a>
			      </li>
		     
		  
		      
			      <li class="post">
			        <a href="15620392963346.html">loggging模块</a>
			      </li>
		     
		  
		      
		  
		      
		  
		      
		  
		      
		  
		      
		   
		  		</ul>
                </div>
              </div>
        </div><!-- sidebar -->
      </div><!-- hide for small -->
</div><!-- large 4 -->

</div><!-- row -->

 <div class="page-bottom clearfix">
  <div class="row">
   <p class="copyright">Copyright &copy; 2015
Powered by <a target="_blank" href="http://www.mweb.im">MWeb</a>,&nbsp; 
Theme used <a target="_blank" href="http://github.com">GitHub CSS</a>.</p>
  </div>
</div>

        </section>
      </div>
    </div>

  
    

    <script src="asset/js/foundation.min.js"></script>
    <script>
      $(document).foundation();
      function fixSidebarHeight(){
        var w1 = $('.markdown-body').height();
          var w2 = $('#sidebar').height();
          if (w1 > w2) { $('#sidebar').height(w1); };
      }
      $(function(){
        fixSidebarHeight();
      })
      $(window).load(function(){
          fixSidebarHeight();
      });
     
    </script>

    
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><script type="text/x-mathjax-config">MathJax.Hub.Config({TeX: { equationNumbers: { autoNumber: "AMS" } }});</script>


  </body>
</html>
